import instance from "./axiosConfig";

interface ResponseDataType {
    code: number;
    message: string;
    data: any;
    token?: string,
}

// export function httpGet(url: string, params: object = {}): Promise<ResponseDataType> {
//     return instance.get(url, { params });
// };
// export function httpDelete(url: string, params: object = {}): Promise<ResponseDataType> {
//     return instance.delete(url, { params });
// };
// export function httpPost(url: string, params: object = {}): Promise<ResponseDataType> {
//     return instance.post(url, params);
// };
// export function httpPut(url: string, params: object = {}): Promise<ResponseDataType> {
//     return instance.put(url, params);
// };

// 所有axios请求的结果，都是一个Promise对象。
// Promise<ResponseDataType>：表示当前数据的类型是Promise，并且Promise里面resolve的数据是ResponseDataType类型
export function httpGet(url: string, params: object = {}): Promise<ResponseDataType> {
    return instance.get(url, { params })
}
export function httpPost(url: string, params: object = {}): Promise<ResponseDataType> {
    return instance.post(url, params)
}
export function httpDelete(url: string, params: object = {}): Promise<ResponseDataType> {
    return instance.delete(url, { params })
}
export function httpPut(url: string, params: object = {}): Promise<ResponseDataType> {
    return instance.put(url, params)
}